Skip to content

Upgrades to allow the sample app to work in the current environment - #226

Open
k6-1994 wants to merge 3 commits into
https-deeplearning-ai:mainfrom
k6-1994:main
Open

k6-1994 wants to merge 3 commits into
https-deeplearning-ai:mainfrom
k6-1994:main

Conversation

@k6-1994

@k6-1994 k6-1994 commented Nov 27, 2026

Copy link
Copy Markdown

Summary

The chatbot was calling claude-sonnet-4-20250514 (Claude Sonnet 4), which was retired on June 15, 2026. Every query to /api/query therefore failed with an HTTP 500. This PR moves the app to Claude Sonnet 5.5 (claude-sonnet-5-5) and upgrades the Anthropic Python SDK from 0.58.2 to 2.14.0, which also moves requests to API version 2026-10-21.

Changes

1. Migrate to Claude Sonnet 5.5 (11fdfcc)

  • backend/config.py: ANTHROPIC_MODEL is now claude-sonnet-5-5.
  • backend/ai_generator.py:
    • Removed temperature: 0. Sonnet 5.5 rejects non-default sampling parameters.
    • Raised max_tokens from 800 to 4096. Thinking is on by default and its tokens count toward the limit, so 800 could truncate answers.
    • Set effort to low to keep short Q&A responses fast and inexpensive.
    • Added _extract_text() to replace response.content[0].text. A response can now begin with a thinking block, so the helper joins only the text blocks. It also returns a short fallback message when stop_reason is refusal.

2. Upgrade the Anthropic Python SDK to 2.14.0 (f392f79)

  • pyproject.toml: pinned anthropic==2.14.0.
  • uv.lock: regenerated. It now includes httpx2, the SDK's HTTP dependency, which is the maintained fork of httpx published by Pydantic.
  • backend/ai_generator.py: output_config is now passed as a native parameter. The extra_body workaround was only needed because the old SDK didn't support it.

SDK 2.x sends anthropic-version: 2026-10-21 by default. I checked this code against that version's breaking changes:

Change Impact on this codebase
temperature / top_p / top_k rejected Already removed in commit 1
document blocks in assistant messages rejected Not used
citations on user text blocks rejected Not used
Admin / Analytics API field removals Not used
API key sent as Authorization: Bearer instead of X-Api-Key No effect: the app uses a single api_key and no proxy
MessageParam becomes a per-role union No effect: messages are built as dict literals

Migration guide: https://platform.claude.com/docs/en/api/migration-2026-10-21

Testing

  • python -m compileall passes on backend/.
  • The outgoing request header was confirmed as anthropic-version: 2026-10-21.
  • A live direct-answer request (no tool call) returned a correct reply.
  • A live tool-use request (search_course_content → second call without tools) returned an answer built from the tool's result.
  • An end-to-end POST /api/query through the FastAPI app with ChromaDB search returned 200. The answer drew on the course content, and the sources were correct (MCP: Build Rich-Context AI Apps with Anthropic - Lesson 1).

The repository has no automated test suite.

Notes for reviewers

  • License change: the Anthropic SDK is licensed under Apache 2.0 from 2.x onward (it was MIT before). No code change is needed, but dependency license tracking may need updating.
  • Line endings: backend/ai_generator.py uses CRLF line endings, and the edits preserve them. The diff contains only the real changes.

🤖 Generated with Claude Code

Scott M. Litvinoff and others added 3 commits November 26, 2026 19:12
claude-sonnet-4-20250514 was retired on 2026-06-15, so every query failed.

- Switch ANTHROPIC_MODEL to claude-sonnet-5-5
- Drop temperature (non-default sampling params are rejected)
- Raise max_tokens to 4096 since thinking tokens count toward it
- Set effort to low via extra_body (pinned SDK lacks output_config)
- Extract text blocks explicitly instead of content[0], skipping
  thinking blocks and handling refusals

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SDK 2.x sends API version 2026-10-21 by default.

- Pin anthropic==2.14.0 and regenerate uv.lock (adds httpx2, the
  SDK's HTTP dependency)
- Pass output_config as a native parameter instead of via extra_body

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant